package com.ys.controller.web.account;

import com.bo.vo.W;
import com.ys.config.MenuId;
import com.ys.entity.account.TcwAdvanceAccountRecharge;
import com.ys.entity.sys.YsProcInst;
import com.ys.enume.flow.YsProcInstEnum;
import com.ys.service.account.TcwAdvanceAccountRechargeService;
import com.ys.service.sys.CommonApiService;
import com.ys.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 预支账户充值单
 */
@Controller
@RequestMapping("/web/account/tcwAdvanceAccountRecharge")
public class WebTcwAdvanceAccountRechargeController {
	private static final Logger logger = LoggerFactory.getLogger(WebTcwAdvanceAccountRechargeController.class);


	@Autowired
	private CommonApiService<TcwAdvanceAccountRecharge> commonApiService;


	@Autowired
	private TcwAdvanceAccountRechargeService tcwAdvanceAccountRechargeService;



	/*
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response){
		TcwAdvanceAccountRecharge entity = new TcwAdvanceAccountRecharge();
		try {
			String bid = commonApiService.getCommonNextBid(MenuId.TCW_AdvanceAccountRecharge);
			entity.setBid(bid);
			return commonApiService.toAdd(model, entity, MenuId.TCW_AdvanceAccountRecharge, null, null);
		} catch (Exception e) {
			logger.error("新增页面出错：",e.getMessage(),e);
			return W.error(model, e.getMessage());
		}
	}



	/*
	 * 编辑
	 */
	@GetMapping("/toEdit")
	public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response,String bid){
		try {
			Map<String,Object> entity = tcwAdvanceAccountRechargeService.getExtraParam(bid);
			//获取审核时间
			YsProcInst ysProcInst = new YsProcInst().setBid(entity.get("bid").toString()).queryFirst();

			Integer onProcess = ysProcInst.getStateFlow() == YsProcInstEnum.StateFlow.INIT.value ? 0 : 1;
			model.addAttribute("onProcess", onProcess);
			return commonApiService.toEdit(model, Long.parseLong(entity.get("id").toString()), new TcwAdvanceAccountRecharge(), MenuId.TCW_AdvanceAccountRecharge, entity, null);
		} catch (Exception e) {
			logger.error("员工入职申请编辑页面出错：",e.getMessage(),e);
			return W.error(model, e.getMessage());
		}
	}



}






